<html>
<head><meta charset="utf-8"><title>Crate wide allocators · t-libs/wg-allocators · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/index.html">t-libs/wg-allocators</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/Crate.20wide.20allocators.html">Crate wide allocators</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="176363901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/Crate%20wide%20allocators/near/176363901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Droste <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/Crate.20wide.20allocators.html#176363901">(Sep 23 2019 at 12:36)</a>:</h4>
<p>Hey all!</p>
<p>First of all, I'd like to say that I'm really excited about the fact that there's a working group exploring how custom allocator support could be extended for Rust!</p>
<p>After giving the <code>#[global_allocator]</code> concept a try, I was wondering if there was also the idea of having crate wide allocators; so having something in-between fully global or per container.</p>
<p>As I'm working with real-time audio it'd be nice being able to scope custom allocators at a crate level since constraints around allocations are consistent within those crates.</p>
<p>On that note, if there's interest or even ongoing process in that area, I'm happy to help!</p>



<a name="176384669"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/Crate%20wide%20allocators/near/176384669" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/Crate.20wide.20allocators.html#176384669">(Sep 23 2019 at 16:26)</a>:</h4>
<p>I'm not sure how crate-wide allocators should or even could work.</p>



<a name="176384682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/Crate%20wide%20allocators/near/176384682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/Crate.20wide.20allocators.html#176384682">(Sep 23 2019 at 16:26)</a>:</h4>
<p>You can allocate something in a crate, and deallocate it on a different crate</p>



<a name="176384706"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/Crate%20wide%20allocators/near/176384706" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/Crate.20wide.20allocators.html#176384706">(Sep 23 2019 at 16:26)</a>:</h4>
<p>Yet which crate allocated an object is not stored anywhere</p>



<a name="176384751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/Crate%20wide%20allocators/near/176384751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/Crate.20wide.20allocators.html#176384751">(Sep 23 2019 at 16:27)</a>:</h4>
<p>e.g. <code>pub fn foo() -&gt; Vec&lt;i32&gt;;</code> which can be called from other crates, the <code>Vec&lt;i32&gt;</code> type does not say which crate allocated the <code>Vec</code>, so... how would they know which allocator to use to free it ?</p>



<a name="176544516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/Crate%20wide%20allocators/near/176544516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Droste <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/Crate.20wide.20allocators.html#176544516">(Sep 25 2019 at 08:39)</a>:</h4>
<p>Thanks for giving this some thought. And yeah, makes sense.  I guess, I was thinking about it in terms of combining distinct static libs (<code>.a</code>), assuming it would work having separate allocators in that scenario.</p>



<a name="176558508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/Crate%20wide%20allocators/near/176558508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/Crate.20wide.20allocators.html#176558508">(Sep 25 2019 at 12:23)</a>:</h4>
<p>With custom allocators, you can just use <code>type MyBox&lt;T&gt; = Box&lt;T, MyAlloc&gt;;</code> in your crate.</p>



<a name="176558588"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/Crate%20wide%20allocators/near/176558588" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/Crate.20wide.20allocators.html#176558588">(Sep 25 2019 at 12:24)</a>:</h4>
<p>That makes the allocator part of the type and your types know how to deallocate themselves</p>



<a name="176558619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/Crate%20wide%20allocators/near/176558619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/Crate.20wide.20allocators.html#176558619">(Sep 25 2019 at 12:25)</a>:</h4>
<p>(deleted)</p>



<a name="176684481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/Crate%20wide%20allocators/near/176684481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Droste <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/Crate.20wide.20allocators.html#176684481">(Sep 26 2019 at 18:37)</a>:</h4>
<p>That's great! But looking at the issues from the <code>wg-allocators</code> repo, there's no way yet to use custom allocators for <code>Box</code> or containers from <code>std::collection</code>, right?</p>



<a name="176761386"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/Crate%20wide%20allocators/near/176761386" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sydney Acksman <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/Crate.20wide.20allocators.html#176761386">(Sep 27 2019 at 16:23)</a>:</h4>
<p>Not yet, I believe we're waiting on stability attributes for type parameters atm</p>



<a name="176770749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/Crate%20wide%20allocators/near/176770749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Droste <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/Crate.20wide.20allocators.html#176770749">(Sep 27 2019 at 18:09)</a>:</h4>
<p>I see, thanks for clarifying.</p>



<a name="177431641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/Crate%20wide%20allocators/near/177431641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/Crate.20wide.20allocators.html#177431641">(Oct 05 2019 at 21:15)</a>:</h4>
<blockquote>
<p>Not yet, I believe we're waiting on stability attributes for type parameters atm</p>
</blockquote>
<p>Can confirm, this is the first step we have to take before landing anything upstream.<br>
This is the issue in the WG repo: <a href="https://github.com/rust-lang/wg-allocators/issues/2" target="_blank" title="https://github.com/rust-lang/wg-allocators/issues/2">https://github.com/rust-lang/wg-allocators/issues/2</a><br>
And the WIP PR: <a href="https://github.com/rust-lang/rust/pull/65083" target="_blank" title="https://github.com/rust-lang/rust/pull/65083">https://github.com/rust-lang/rust/pull/65083</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>